#include <stdio.h>
#include <stdlib.h>

// 定义链表节点结构
typedef struct Node {
    int data;
    struct Node* next;
} Node;

// 创建新节点
Node* createNode(int data) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}

// 反转链表
Node* reverseList(Node* head) {
    Node* prev = NULL;
    Node* current = head;
    Node* next = NULL;

    while (current != NULL) {
        next = current->next; // 保存下一个节点
        current->next = prev; // 反转当前节点指针
        prev = current;       // 移动 prev 到当前节点
        current = next;       // 移动到下一个节点
    }
    return prev; // 返回新的头节点
}

// 打印链表
void printList(Node* head) {
    Node* current = head;
    while (current != NULL) {
        printf("%d ", current->data);
        current = current->next;
    }
    printf("\n");
}

int main() {
    int n;
    scanf("%d", &n); 

    if (n <= 0) {
        return 0; 
    }

    Node* head = NULL;
    Node* tail = NULL;

    // 读取链表元素并创建链表
    for (int i = 0; i < n; i++) {
        int value;// 读取元素
        scanf("%d", &value);
        Node* newNode = createNode(value);// 创建节点
        if (head == NULL) {
            head = newNode; 
            tail = newNode; 
        } else {
            tail->next = newNode; // 将新节点连接到链表
            tail = newNode;        // 更新尾节点
        }
    }

    // 反转链表
    head = reverseList(head);

    // 打印反转后的链表
    printList(head);

    // 释放链表内存
    Node* current = head;
    while (current != NULL) {
        Node* temp = current;
        current = current->next;
        free(temp); // 释放当前节点
    }

    return 0;
}
